package com.litxuf.web.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;

import com.litxuf.FinalInformation;
import com.litxuf.logic.member.dao.model.School;

public class MemberLoginFilter  implements Filter {
	Logger logger=Logger.getLogger(this.getClass());
	public void destroy() {
		// TODO Auto-generated method stub

	}

	public void doFilter(ServletRequest arg0, ServletResponse arg1,
			FilterChain arg2) throws IOException, ServletException {
		HttpServletRequest req = (HttpServletRequest) arg0;
		HttpServletResponse rsp = (HttpServletResponse) arg1;
		HttpSession session = req.getSession(true);
		
		School sm = (School) req.getSession().getAttribute(
				FinalInformation.UserFrontLogin);

		if (sm == null) {
			logger.info("--> 用户未登录呢 跳转到登录页面");
			rsp.sendRedirect(rsp.encodeRedirectURL(req.getContextPath())+ "/login.jsp");
			return;
		}
		 
		arg2.doFilter(arg0, arg1);
	}

	public void init(FilterConfig arg0) throws ServletException {

	}

}
